/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.servlet;

import cn.webrx.utils.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Locale;

/**
 * <p>Project: javaweb - Reg
 * <p>Powered by webrx On 2022-03-11 09:52:35
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@WebServlet("/reg")
public class Reg extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String a = req.getParameter("account");//account
        String p = req.getParameter("password");//passwd
        String name = req.getParameter("truename");//truename
        String ip = "0:0:0:0:0:0:0:1".equals(req.getRemoteAddr().toString()) ? "127.0.0.1" : req.getRemoteAddr();

        DbUtil du = new DbUtil();
        int row = du.update("insert into wx_member set account=?,passwd=?,truename=?,regtime=?,regip=?",a,p,name, Timestamp.valueOf(LocalDateTime.now()),ip);

        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }
}
